import React, { Component } from 'react';
import Refchild from './child';
class parentRef extends Component {
  state = {}
  // 使用ref将父组件的函数绑定到子组件上
  // 父组件的函数会有参数 参数就代表子组件的方法...  
  channelChild = () => {
    this.childRef.look('父组件修改了')
  }
  setChildRef = (ref) => {
    this.childRef = ref
  }
  render () {
    return (<>
      <h2>使用ref传值</h2>
      <Refchild ref={this.setChildRef} />
      <button onClick={this.channelChild}>使用ref访问子组件</button>
    </>);
  }
}

export default parentRef;